# Maintainer: David Grayson <davidegrayson@gmail.com>

_realname=win7appid
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1
pkgrel=4
pkgdesc='Windows 7 (and up) shortcut application id tool'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://code.google.com/p/win7appid'
license=('custom')
makedepends=("gzip"
             "${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip')
source=(
    "86ca5a388b5f8786b585037c95832bcf65e22e97.patch"
    "6f5a32543dce6a452fb852ddffdd8f85f7af69af.patch"
    "win7appid.1"
    "LICENSE.txt"
)

sha256sums=('429c34f931d02a4263bb8b2c618e3fd044e2bbac3fc7e63b49c1f2b715035f2f'
            'c4840755e9ce9cee28be4cef20bcc2885f981e795ab1e2fe208990fdd17d4a42'
            'c012c8069b09a86a991ab6010d32b59480c6f9e1ae28b57e0b86788ce15b73ea'
            'daafcc2b56af560dde656a591c8ea5d29f200add98e96fd0e1eb7616a99e227a')

prepare() {
    patch -l -i ../86ca5a388b5f8786b585037c95832bcf65e22e97.patch
    patch -l -i ../6f5a32543dce6a452fb852ddffdd8f85f7af69af.patch
    gzip < win7appid.1 > win7appid.1.gz
}

build() {
  mkdir -p "build-${MINGW_CHOST}"
  cd "build-${MINGW_CHOST}"

  g++ -O1 -municode -DWIN32_LEAN_AND_MEAN=1 -DUNICODE -D_UNICODE \
    ../*.cpp -lole32 \
    -o win7appid.exe
}

package() {
  r="${pkgdir}${MINGW_PREFIX}"
  mkdir -p "${r}/share/licenses/${_realname}" \
    "${r}/share/man/man1" "${r}/bin"

  install -m644 LICENSE.txt -t "${r}/share/licenses/${_realname}"
  install -m644 win7appid.1.gz -t "${r}/share/man/man1"

  cd "build-${MINGW_CHOST}"
  install -m755 win7appid.exe -t "${r}/bin"
}
